<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>历史订单</title>
   <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/weui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <script src="../script/jquery-3.2.1.js"></script>
    <script src="../script/switch.js"></script>
    <script src="../script/api.js"></script>
    <style>
        .empty{ text-align: center; padding: 120px 0; }
    </style>
</head>
<body>
	<div id="historyNode"></div>
</body>
<script type="text/javascript">
var urlStr = "101.207.250.6:8520";
var account = $api.getStorage("dl_phone");    
/*
apiready = function(){
	alert(1);
	crossDomainRequest1();
	alert(2);
};
*/
//发起订单历史记录获取请求
function crossDomainRequest1() {
    var url = 'http://www.scscpt.com:8520/wzrz/getorderhistory';
	api.ajax({
	    url: url,
	    method: 'post',
	    dataType: 'text',
	    header:{
	    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
	    },
	    data: {
	    	values:{
	            account:account
	    	}
	    }
	}, function(ret, err) {
	    if (ret) {
	    	var MSG5 = JSON.stringify(ret) ;	    	
      		liOrderMsg(MSG5);		
	    } else {
	        api.alert({ msg: JSON.stringify(err) });
	    }
	});
	/*
  if (xhr) {
    xhr.open('POST', url, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.onreadystatechange = handler;
    xhr.send("account=18190925709");
  } else {
  	
  }
    //获取历史订单信息
    function handler(evtXHR) {
      if (xhr.readyState == 4) {
        if (xhr.status == 200) {
          var response = xhr.responseText;
          liOrderMsg(response);
        } else {
          //alert("不允许跨域请求。");
        }
      }
      else {     
      }
    }*/	    
}    
    //展示
    function liOrderMsg(response){
    var str = response.split("*");
        if(str[1]!="</string>"){
      	for(var i=1;i<str.length-1;i++){
      		var msg = str[i].split("|");
      		var ordid = msg[0]
			var name = msg[1];
			var cardno = msg[2];
			var code = msg[3];
			var gender = msg[4];
			gender = switchGender(gender);
			var birth = msg[5];
			var address = msg[6];
			var cljg = msg[7];
			var stationid = msg[8];
			var rzjd = msg[9];
			var rzfh = msg[10];
			var createTime = msg[11];
			var s_massage = msg[12];
			var nation = switchNation(code);
			var secNo = secCardNo(cardno);
			var box = document.getElementById("historyNode");
			var li = document.createElement("div"); 
			var boxStr = "";
			if('0' == cljg){
				boxStr = 
				'<div class="weui_cells_title">入住状态：订单进行中,请稍后...<br/>'+
					'订&nbsp;单&nbsp;号:'+ordid+'<br/>'+
					'订单时间:'+createTime+'</div>'+
				'<div class="weui_cells">'+
        			'<div class="weui_cell">'+
            			'<div class="weui_cell_bd weui_cell_primary">';
			}else if('2' == cljg){
				boxStr = 
				'<div class="weui_cells_title">订单已完成,入住成功<br/>'+
					'订&nbsp;单&nbsp;号:'+ordid+'<br/>'+
					'订单时间:'+createTime+'</div>';
				boxStr += 
        			'<div class="weui_cell">'+
            			'<div class="weui_cell_bd weui_cell_primary">'+
            			"入住酒店："+rzjd+'<br/>'+
            			"入住房号："+rzfh+'<br/>';
			}else if('1' == cljg){
				boxStr = '<div class="weui_cells_title">入住失败</div>'+
					'订&nbsp;单&nbsp;号:'+ordid+'<br/>'+
					'订单时间:'+createTime+'<br/>'+
					'失&nbsp;败&nbsp;码:'+s_massage+'<br/>'+
					'</div>'+
				'<div class="weui_cells">'+
        			'<div class="weui_cell">'+
            			'<div class="weui_cell_bd weui_cell_primary">';
			}
			li.style.textAlign = "left";
			li.style.marginLeft = "20px";
			li.innerHTML = boxStr + 
                		"姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名："+name+'<br/>'+
                		"身份证号："+secNo+'<br/>'+
                		"民&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;族："+nation+'<br/>'+
                		"性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别："+gender+'<br/>'+
                		"出生日期："+birth+'<br/>'+
                		"详细住址："+address+
            			'</div>'+
        			'</div>'+
    			'</div>';
			box.appendChild(li);  
      		}
    	}
    }
    //下拉刷新
apiready = function(){
	crossDomainRequest1();
    var param = {};
    param.loadingImgae = './image/loading_more.gif'; //定义刷新小箭头的图片
    param.bgColor = '#ccc';                            //定义下拉刷新区域的背景
    param.textColor = '#fff';                          //定义下拉刷新提示文字的颜色
    param.textDown = '下拉刷新';                     //定义下拉刷新文字
    param.textUp = '松开立即刷新...';                       //定义松开刷新文字
    param.showTime = false;                             //定义是否显示最后一次刷新时间
    api.setRefreshHeaderInfo(param, function(ret, err){
        toDoRequest();
    });
}
function toDoRequest(){
        api.refreshHeaderLoadDone();        //复位下拉刷新
		location.reload();
}

</script>
</html>
